import { HYEventStore } from "hy-event-store"

import { getRankings } from "../server/api_music"

const rankingMap = {0: "newRanking", 1: "hotRanking", 2: "originRanking", 3: "upReanking"}

const rankingStore = new HYEventStore({
    state: {
        newRanking: {},
        hotRanking: {},
        originRanking: {},
        upReanking: {}
    },
    actions: {
        getRankingDataAction(ctx) { 
            for(let i = 0; i < 4; i++ ) {
                getRankings(i).then(res => {
                    const rankingName = rankingMap[i]
                    ctx[rankingName] = res.playlist
                 })
            }
        }
    }
})

export {
    rankingStore,
    rankingMap
}